package com.just521.xinshoutong.view;


import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.ResultReceiver;
import android.text.InputType;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;





public class ToDoEditView extends EditText 
	implements View.OnKeyListener
{
	private   boolean  bdrawbaseline = true;
	private   Context  mContext;
	private InputMethodManager mImm = ((InputMethodManager)getContext().getSystemService(Activity.INPUT_METHOD_SERVICE));
	private myResultReceiver mRstReceiver = new myResultReceiver();
	class myResultReceiver extends ResultReceiver{
		public myResultReceiver(){
			super(null);
		}
		public void onReceiveResult(int resultCode, Bundle resultData){
//			if(resultCode==InputMethodManager.RESULT_UNCHANGED_SHOWN){
//				mImm.hideSoftInputFromWindow(getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
//			}
		}
	}
	private int mLastSelectionPos = -1;
	
	private	int 			mInputMode = 0 ;   // 0 ����   1  ��д
	public ToDoEditView(Context context) {
		super(context);
		setOnKeyListener(this);
		mContext = context;
	}
	
	public ToDoEditView(Context paramContext, AttributeSet paramAttributeSet)
	{
	    super(paramContext, paramAttributeSet);
	    setOnKeyListener(this);
		mContext = paramContext;
//	    ((InputMethodManager)paramContext.getSystemService(Activity.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
	}
	
	public ToDoEditView(Context paramContext, AttributeSet paramAttributeSet, int paramInt)
	{
	    super(paramContext, paramAttributeSet, paramInt);
	    setOnKeyListener(this);
		mContext = paramContext;
	}

	
	public void SetInputMode(int  inputMode)
	{
		mInputMode = inputMode;
//		if(mInputMode==1){
//			((InputMethodManager)getContext().getSystemService(Activity.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
//			requestFocus();
//		}else{
////			setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_FLAG_MULTI_LINE|InputType.TYPE_TEXT_FLAG_CAP_WORDS);
//		}
		
		
	}
	public void showKeyboard(){
		
		setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_FLAG_MULTI_LINE|InputType.TYPE_TEXT_FLAG_CAP_WORDS);
		mImm.showSoftInput(this, InputMethodManager.SHOW_FORCED );
		
	}
	
	
	  public boolean onKey(View paramView, int paramInt, KeyEvent paramKeyEvent)
	  {
		  boolean b = false;
		  do{
			 if(paramInt==KeyEvent.KEYCODE_ENTER&&paramKeyEvent.getAction()==KeyEvent.ACTION_DOWN){
				  mlistener.onEnterClick();
				  b = true;
				  break;
			  }
		  }while(false);
		  
		  return b;
	  }
	  OnKeyClickListner mlistener;
	  public void setOnKeyClickListner(OnKeyClickListner listener){
		  mlistener=listener;
	  }
	  public interface OnKeyClickListner{
		  void onEnterClick();
	  }
	  
}
